package view.micro.background
{
	import flash.display.GradientType;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Matrix;
	import model.micro.Battle;
	import model.micro.BoundingBox;
	import util.Settings;
	import view.micro.IMicroSprite;
	
	/**
	 * Draws the background of the battle.
	 */
	public class BattleBackgroundSprite extends Sprite implements IMicroSprite
	{
		private var battle:Battle;
		public var clouds:Vector.<CloudSprite>;
		
		public function BattleBackgroundSprite(battle:Battle)
		{
			this.battle = battle;
			mouseChildren = false;
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			//ground
			var ground_box:BoundingBox = battle.ground.getBoundingBox();
			var matrix:Matrix = new Matrix();
			matrix.createGradientBox(ground_box.width, ground_box.height, Math.PI / 2, 0, 0);
			graphics.beginGradientFill(GradientType.LINEAR, [0x44BB00, 0x558800], [1, 1], [0, 255], matrix);
			graphics.drawRect(ground_box.left, ground_box.bottom, ground_box.width, ground_box.height);
			graphics.endFill();
			
			//sky
			matrix.createGradientBox(stage.stageWidth, stage.stageHeight, Math.PI / 2, 0, 0);
			graphics.beginGradientFill(GradientType.LINEAR, [0xDDEEFF, 0x88BBFF], [1, 1], [0, 255], matrix);
			graphics.drawRect(ground_box.left, ground_box.top, ground_box.width, Settings.METER * 80);
			graphics.endFill();
			
			for (var i:int = 0; i < 10; i++)
			{
				addChild(new CloudSprite());
			}
			
			for (i = 0; i < 5; i++)
			{
				addChild(new BirdSprite());
			}
		}
		
		public function update():void
		{
			for (var i:int = 0; i < numChildren; i++)
			{
				(getChildAt(i) as IMicroSprite).update();
			}
		}
		
		public function readyToRemove():Boolean
		{
			return false;
		}
	
	}

}